package com.ape.mapsa.converters;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import com.ape.mapsa.common.constants.TipoMaterial;

@FacesConverter(value = "DensidadConverter")
public class DensidadConverter implements Converter {
	@Override
	public Object getAsObject(FacesContext context, UIComponent component, String value) {
		for (TipoMaterial tm : TipoMaterial.values()) {
			if (tm.getValor().toString().equals(value)) {
				return tm;
			}
		}
		return null;
	}

	@Override
	public String getAsString(FacesContext context, UIComponent component, Object value) {
		for (TipoMaterial tm : TipoMaterial.values()) {
			if (tm.getValor().toString().equals(value.toString())) {
				return tm.getNombre();
			}
		}
		return "";
	}
}
